<template>
  <div>
    <nav-top :nav_list="nav_list" :windowsize="windowsize" @change="changeNav"></nav-top>
    <!-- 内容 -->
    <router-link class="news-list" v-for="item in list" :to="'detail/'+item.id">
      <div class="news-cover-box">
        <img v-lazy="item.cover" class="news-cover" />
      </div>
      <div class="news-body">
        <div class="news-title">{{item.title}}</div>
        <div class="news-time">2019-09-26</div>
        <div class="news-content" v-html="item.content"></div>
        <div class="news-btns">
          <img src="https://jingye.oss-cn-qingdao.aliyuncs.com/news/right.png" class="news-icon" />
          <span class="news-btns-title">View</span>
        </div>
        <div class="news-btn-mobile">
          <span>
            了解详情
            <img
              src="https://jingye.oss-cn-qingdao.aliyuncs.com/news/right-1.png"
              class="btn-icon"
            />
          </span>
        </div>
      </div>
      <div class="news-lit-line"></div>
    </router-link>
    <div class="pages-body" v-if="list.length">
      <page-box @change="changePage" :last="last_page" :page="current_page"></page-box>
    </div>
  </div>
</template>

<script>
import navTop from "../../components/nav/nav-one.vue";
import pageBox from "../../components/page/pc-style.vue";

export default {
  components: { navTop, pageBox },
  data() {
    return {
      nav_list: [
        { name: "全部", state: 0 },
        { name: "公司新闻", state: 1 },
        { name: "综合资讯", state: 2 }
      ],
      last_page: 1,
      current_page: 1,
      windowsize: true,
      list: [],
      state: 0
    };
  },
  mounted() {
    window.onresize = () => {
      this.windowsize = this.windowsize ? false : true;
    };
    this.getData();
  },
  methods: {
    getData() {
      this.list = [];
      this.ajaxs("index/getNews", {
        data: { page: this.current_page, state: this.state },
        success: res => {
          this.list = res.msg.data;
          this.current_page = res.msg.current_page;
          this.last_page = res.msg.last_page;
        }
      });
    },
    //切换导航
    changeNav(key) {
      this.state = key.state;
      this.current_page = 1;
      this.getData();
    },
    //分页
    changePage(e) {
      var scrollTop =
        document.documentElement.scrollTop || document.body.scrollTop;
      document.documentElement.scrollTop = document.body.scrollTop = 0;
      this.current_page = e;
      this.getData();
    }
  }
};
</script>

<style scoped>
@import url("../../assets/css/news/index.css");
</style>